package com.shitou.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.shitou.dao.UserDao;
import com.shitou.pojo.User;

@Repository
@Transactional
public class UserService {

	@Resource
	private UserDao dao;
	
	
	public void save(User user) {
		dao.save(user);
	}
	
	public User login(User user) {
		return dao.login(user);
	}
	
	@Transactional(readOnly=true)
	public List<User> find() {
		return dao.findAll();
	}
	
	@Transactional(readOnly=true)
	public List<User> findAll() {
		return dao.findAll();
	}

	public User findById(int id) {
		return dao.findById(id);
	}
	
	public void del(int id) {
		dao.del(id);
	}

	public List<User> findByIds(String ids) {
		String[] sids = ids.split(",");
		Integer[] iids = new Integer[sids.length];
		for (int i = 0; i < sids.length; i++) {
			iids[i] = Integer.valueOf(sids[i]);
		}
		return dao.findByIds(iids);
	}

	public User findByName(String username) {
		return dao.findUniqueByProperty("name", username);
	}
}
